<template>
	<view>
		<u-image
			v-for="(item, index) in srcList" :key="index"
			@click="itemClick(index)"
			mode="widthFix"
			:src="decodeURIComponent(item)">
		</u-image>
	</view>
</template>

<script>
	import { getDocument, getDocumentDir } from '@/api/document.js'
	export default {
		data() {
			return {
				isDir: 0,
				document: null,
				srcList: [],
			}
		},
		onLoad(options) {
			console.log(options);
			this.isDir = parseInt(options.isDir);
			this.id = options.id;
			uni.setNavigationBarTitle({
			　　title: options.title
			})
			if (this.isDir === 1) {
				this.getDocument();
			} else {
				this.getDocumentDir();
			}
		},
		methods: {
			getDocument() {
				getDocument(this.id).then(res => {
					console.log(res);
					this.document = res.data;
					this.srcList = this.document.resURL.split('|');
					console.log(this.srcList);
					
				})	
			},
			
			getDocumentDir() {
				getDocumentDir(this.id).then(res => {
					console.log(res);
					this.document = res.data;
				})
			},
			
			itemClick(current) {

				uni.previewImage({
					urls: this.srcList,
					current: current,
				});
			}
		}
	}
</script>

<style>

</style>
